#include <iostream>
#include "Gameboard.h"


using namespace std;

Gameboard::Gameboard(int x, int y){
	width = x;
	height = y;
	generate();
	}

void Gameboard::setBoard(int x, int y){
	width = x;
	height = y;
	}

int Gameboard::getWidth(){
	return width;
	}

int Gameboard::getHeight(){
	return height;
	}

void Gameboard::placeHeroOnBoard(){
	if (hero != 0)
		gameBoard[hero->getXLocation()][hero->getYLocation()]='H';
	}

void Gameboard::setHero(Hero* player){
	hero = player;

	}

void Gameboard::generate(){
	char **dynamicArray = 0; //temp
	dynamicArray = new char *[width] ;
	for( int i = 0 ; i < width ; i++ )
		dynamicArray[i] = new char[height]; //initialize width                
	for (int i = 0; i<width; i++)
		for (int k = 0; k<height; k++) //initialize height
			{          
			if (k==0||k==height-1)
				dynamicArray[i][k] = '-';
			else if
				(i==0||i==width-1)
				dynamicArray[i][k] = '|';
			else
				dynamicArray[i][k]= ' ';
			}       
		gameBoard = dynamicArray;
	}

void Gameboard::printBoard(){
	for (int n = 0; n<height; n++){       
		for (int a =0; a<width; a++){
			cout<<gameBoard[a][n];
			}
		cout<<"\n";     
		}

	}

void Gameboard::moveHeroXAxis(int x){
	int xLoc;
	int tempLoc = hero->getXLocation()+x;
	gameBoard[hero->getXLocation()][hero->getYLocation()]=' ';
	if (isValidXMove(tempLoc))
		xLoc = tempLoc;
	else
		xLoc = hero->getXLocation();
	hero->moveHeroAxis(new Point(xLoc, hero->getYLocation()));
	gameBoard[hero->getXLocation()][hero->getYLocation()]='H';
	
	}


void Gameboard::moveHeroYAxis(int y){
	int yLoc;
	int tempLoc =hero->getYLocation()+y;

	if (isEvent(hero->getXLocation(), tempLoc))
		gameBoard[hero->getXLocation()][hero->getYLocation()]=' ';
	if (isValidYMove(tempLoc))
		yLoc = tempLoc;
	else
		yLoc = hero->getYLocation();
	hero->moveHeroAxis(new Point(hero->getXLocation(), yLoc));
	gameBoard[hero->getXLocation()][hero->getYLocation()]='H';
	

	}

void Gameboard::placeMinotaur(Minotaur* minotaur){
	int xLoc;
	int yLoc;
	xLoc = minotaur->getXLocation();
	yLoc = minotaur->getYLocation();
	gameBoard[xLoc][yLoc] = 'M';


	}


void Gameboard::placeGoblin(Goblin* goblin){
	int xLoc;
	int yLoc;
	xLoc = goblin->getXLocation();
	yLoc = goblin->getYLocation();
	gameBoard[xLoc][yLoc] = 'G';


	}

bool Gameboard::isValidXMove(int x){
	if ((x) > getWidth()-2)
			return false;
	else if ( x <= 0)
			return false;
	else
		return true;
	
	}
bool Gameboard::isValidYMove( int y){
	if (y > getHeight()-2) 
			return false;
	else if (y <=0)
			return false;
	else
		return true;

	}

bool Gameboard::isEvent(int x, int y){
	if(gameBoard[x][y] != '' && gameBoard[x][y] != null)
		return false;
	else
		return true;

	}
	



void Gameboard::placeRelic(Sword* swordOfDestiny){


	}

